﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for PanelBusiness
/// </summary>
public class PanelBusiness
{
	public PanelBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool Insert(PanelEntities item)
    {
        bool flat = false;
        string[] para = { "@controlID", "@channelID", "@cellID","@pannelPriority","@pannelHeader","@displayContrainer","@displayInAllChannel","@field1","@field2" };
        string[] values = { item._controlSourceFile,item._channelID.ToString(),item._cellID.ToString(),item._pannelPriority.ToString(),item._pannelHeader,
                                item._displayContrainer.ToString(),item._displayInAllChannel.ToString(),item._field1,item._field2};
        if (DataAccess.getExecProcedure("sp_InsertPanel", para, values) > 0)
        {
            flat = true;
        }
        else
            flat = false;
        return flat;
    }
    public bool Edit(PanelEntities item)
    {
        bool flat = false;
        string[] para = { "@panelID", "@controlID", "@channelID", "@cellID", "@pannelPriority", "@pannelHeader", "@displayContrainer", "@displayInAllChannel", "@field1", "@field2" };
        string[] values = { item._controlSourceFile,item._channelID.ToString(),item._cellID.ToString(),item._pannelPriority.ToString(),item._pannelHeader,
                                item._displayContrainer.ToString(),item._displayInAllChannel.ToString(),item._field1,item._field2}; ;
        if (DataAccess.getExecProcedure("sp_UpdatePanel", para, values) > 0)
            flat = true;
        else
            flat = false;
        return flat;
    }
    public bool Delete(UserEntities item)
    {
        if (DataAccess.getExecProcedure("sp_DeleteUser", new string[] { "@userID" }, new string[] { item._userID.ToString() }) > 0)
            return true;
        else
            return false;
    }
    public DataTable getAllPanel()
    {
        return DataAccess.DataTable_Query("exec sp_GetPanel '0'");
    }

    public PanelEntities getPanel(int id)
    {
        DataTable dt = DataAccess.DataTable_Query("exec sp_GetPanel '" + id.ToString() + "'");
        PanelEntities item = null;
        if (dt != null)
        {
            item = new PanelEntities();
            DataRow row = dt.Rows[0];
            item._panelID = int.Parse(row["panelID"].ToString());
            item._controlSourceFile = row["controlSourceFile"].ToString();
            item._channelID = int.Parse(row["channelID"].ToString());
            item._cellID = int.Parse(row["cellID"].ToString());
            item._pannelPriority = int.Parse(row["pannelPriority"].ToString());
            item._pannelHeader = row["pannelHeader"].ToString();
            item._displayContrainer = row["displayContrainer"].ToString();            
            item._field1 = row["field1"].ToString();
            item._field2 = row["field2"].ToString();
        }
        return item;
    }
    public ArrayList getPanelByChanel(int id)
    {
        
        DataTable dt= DataAccess.DataTable_Query("exec sp_GetPanelByChanel '" + id.ToString() + "'");
        ArrayList items = new ArrayList();
        PanelEntities item = null;
        if (dt != null)
        {            
            
            for (int i=0; i < dt.Rows.Count; i++)
            {
                item = new PanelEntities();
                DataRow dr = dt.Rows[i];
                item._panelID = int.Parse(dr["panelID"].ToString());
                item._cellID = int.Parse(dr["cellID"].ToString());
                items.Add(item);
                item = null;
            }
        }
        return items;
    }

    public SqlDataReader getDisplayAll()
    {
        return DataAccess.DataReader_getReader("exec sp_GetDisplayAll");
    }
}